package com.itheima.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @program: itheima-jdk8
 * @description:
 * @author: zhanghz001
 * @create: 2021-01-08 16:27
 **/
public class ThenApplyDemo1 {
    public static void main(String[] args) {
        
        ExecutorService pool = Executors.newFixedThreadPool(3);
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            System.out.println(55);
            System.out.println(Thread.currentThread().getName());
            
            return 55;
        }, pool);
        CompletableFuture<Integer> apply = future.thenApplyAsync(o -> {
            System.out.println(o);
            System.out.println(Thread.currentThread().getName());
            return o * 10;
        }, pool);
        try {
            System.out.println(apply.get());
        } catch (InterruptedException e) {
            apply.cancel(true);
            e.printStackTrace();
        } catch (ExecutionException e) {
            apply.cancel(true);
            e.printStackTrace();
        }
        pool.shutdown();
    }
}
